using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;

using System.Data;

namespace Business
{
    public class LoaiPhongService
    {




		//////////////////////////////////////////////////////////

 		                                                         

		//            Enter code your here                      //


        public static int KiemTraMaLoaiPhongTrongListLoaiPhong(int MaLoaiPhong, List<LoaiPhongDTO> Lst)
        {
            //tra ve -1 neu khong tim thay, tra ve vi tri phong neu tim thay
            for (int i = 0; i < Lst.Count; i++)
            {
                if (MaLoaiPhong == Lst[i].MaLoaiPhong)
                {
                    return i;
                }
            }
            return -1;
        }
        public static int TimViTriLoaiPhongTrongList(int MaLoaiPhong, List<LoaiPhongDTO> Lst)
        {
            for (int i = 0; i < Lst.Count; i++)
            {
                if (MaLoaiPhong == Lst[i].MaLoaiPhong)
                {
                    return i;
                }
            }
            return -1;
        }


        public static bool KiemTraTenTrung(int MaLoaiPhong, string TenLoaiPhong)
        {
            LoaiPhongRepository Repo = new LoaiPhongRepository();
            return Repo.KiemTraTenTrung(MaLoaiPhong, TenLoaiPhong);
        }

        public static LoaiPhongDTO LayTheoTen(string TenLoaiPhong)
        {
            LoaiPhongDTO objDTO = null;
            try
            {
                LoaiPhongRepository Repo = new LoaiPhongRepository();
                objDTO = Repo.LayTheoTen(TenLoaiPhong);
            }
            catch (System.Exception)
            {
            }
            return objDTO;
        }                                           

		//////////////////////////////////////////////////////////

       static public DataTable ConvertListLoaiPhongDTOToDataTable( List<LoaiPhongDTO> lst)
       {
               DataTable dt = new DataTable();
           dt.Columns.Add( "MaLoaiPhong");
           dt.Columns.Add( "TenLoaiPhong");
           dt.Columns.Add( "DonGia");
           for( int i = 0; i < lst.Count; i ++)
           {
               dt.Rows.Add(
                       lst[i].MaLoaiPhong,      
                       lst[i].TenLoaiPhong,      
                       lst[i].DonGia      
                   );
           }
               return dt;
       }
        static public int GetIdentity()
        {
            Data.LoaiPhongRepository repo = new LoaiPhongRepository();
            return repo.GetIdentity();
        }

        static public int Count()
        {
            return LoaiPhongRepository.Count();
        }
        public static bool Them(LoaiPhongDTO objDTO)
        {
                LoaiPhongRepository repo = new LoaiPhongRepository();
                return repo.Them(objDTO);
        }

        public static bool Xoa(int MaLoaiPhong, bool XoaKhoaNgoai=false)
        {
              LoaiPhongRepository Repo = new LoaiPhongRepository();
              return Repo.Xoa(MaLoaiPhong,XoaKhoaNgoai);
        }

        public static void CapNhat(LoaiPhongDTO objDTO)
        {
            try
            {
                LoaiPhongRepository Repo = new LoaiPhongRepository();
                Repo.CapNhat(objDTO);
            }
            catch (System.Exception )
            {
            }
        }

        public static List<LoaiPhongDTO> LayDanhSach()
        {
            List<LoaiPhongDTO> lst = new List<LoaiPhongDTO>();
            try
            {
                LoaiPhongRepository obj = new LoaiPhongRepository();
                lst = obj.LayDanhSach();
            }
            catch (System.Exception )
            {
            }
            return lst;
        }

        static public List<LoaiPhongDTO> LayDanhSach(int Start, int Record)
        {
             Data.LoaiPhongRepository repo = new LoaiPhongRepository();
            return repo.LayDanhSach(Start, Record);
        }

        public static LoaiPhongDTO LayTheoMa(int MaLoaiPhong)
        {
            LoaiPhongDTO objDTO = new LoaiPhongDTO();
            try
            {
                LoaiPhongRepository Repo = new LoaiPhongRepository();
                objDTO = Repo.LayTheoMa(MaLoaiPhong);
            }
            catch (System.Exception )
            {
            }
            return objDTO;
        }
    }
}

